package logic

import (
	"B/Rpc/internal/svc"
	"B/Rpc/model/mysql"
	"B/Rpc/shops"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *GoodAddLogic) GoodAdd(in *shops.GoodAddRequest) (*shops.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{
		UserId:     int(in.UserId),
		GoodsTitle: in.GoodsTitle,
		GoodsStock: int(in.GoodsStock),
		GoodsImage: in.GoodsImage,
		GoodsPrice: float64(in.GoodsPrice),
		GoodsLike:  int(in.GoodsLike),
		Status:     int(in.Status),
	}
	err := g.Create()
	if err != nil {
		return nil, fmt.Errorf("添加失败")
	}

	return &shops.GoodAddResponse{
		Id: int64(g.ID),
	}, nil
}
